<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML" 4.01"//EN" "http://www.w3.org/TR/html4/strict.dtd">
<!-- Created: August 14, 2001-->
<!--
$Id: SurveyAdd.php,v 1.8 2002/02/12 19:17:50 eugenem Exp eugenem $
$Header: /export/home/eugenem/public_html/ComplianceReports/RCS/SurveyAdd.php,v 1.8 2002/02/12 19:17:50 eugenem Exp eugenem $
$Log: SurveyAdd.php,v $
Revision 1.8  2002/02/12 19:17:50  eugenem
Fixed </form> closing tag in the wrong place.

Revision 1.7  2001/11/02 19:10:19  eugenem
Moved HTTP_*_VARS processing to dbc.inc

Revision 1.6  2001/11/02 15:00:26  eugenem
Moved database connect statements to a separate file.

Revision 1.5  2001/10/23 19:11:20  eugenem
Modified so that the form responds to the Add Survey buttons placed in the RepLocation/RepModality reports and sets the MachineID as passed.

Revision 1.4  2001/10/01 19:56:28  eugenem
Made test type SELECT box default to Routine Compliance (1).

Revision 1.3  2001/08/21 15:45:09  eugenem
Changed Tested by SELECT elements to have a blank entry with value=0 for no entry.
Don't bother with querying the database for the record that was just added.

Revision 1.2  2001/08/16 18:16:34  eugenem
*** empty log message ***

Revision 1.1  2001/08/15 15:25:50  eugenem
Initial revision

-->

<html>
<head>
<title>Radiological Equipment Database</title>
<meta name="author" content="Eugene Mah">
<link rev="made" href="mailto:eugenem@ix.netcom.com">
<link rev="home" href="http://home.netcom.com/~eugenem/">
<meta name="description" content="">
<meta name="Keywords" content="">
<meta name="Reply-to" content="eugenem@ix.netcom.com">
<META http-equiv="PICS-Label" content='(PICS-1.1 "http://www.classify.org/safesurf/" l r (SS~~0001))'>
<?PHP
require('functions.inc');
require('dbc.inc');

?>
</head>

<body>
<h1>Radiological Equipment Database</h1>
<?PHP
/*
  Extract the list of machines, testers and test types for use in the
  SELECT form elements
*/
$machines = mysql_query("select MachineID,Description from Machines where Status=\"Active\" order by Description");
$testers = mysql_query("select TesterID,TesterInitials from Testers order by TesterInitials");
$test = mysql_query("select * from TestType");

/*
  If we have entered the form for the first time, none of the form vars
  will be set.  Therefore, check if $MachID has been set, and if not
  do nothing
*/
if (isset($MachID) && (isset($TestDate) || isset($today))) {
  // Go ahead and add the submitted survey into the database
  if (!empty($today)) $TestDate = date("Y-m-d");
  $query = "INSERT INTO Survey2Machine (MachineID) VALUES ($MachID)";
  $result = mysql_query($query)
    or die("<p>Unable to execute query: $query<br />" . mysql_error() . "</p>\n");
  $SurveyID = mysql_insert_id();
  
  $query = "INSERT INTO TestDates (SurveyID,MachineID,TestDate,Tester1ID,Tester2ID,TypeID,Notes,Accession)
            VALUES ($SurveyID,$MachID,\"$TestDate\",$Tester1ID,$Tester2ID,$TypeID,\"$Notes\",\"$Accession\")";
  $result = mysql_query($query)
    or die("<p>Unable to execute query: $query<br />" . mysql_error() . "</p>\n");
  
  echo "<h2>Survey added</h2>\n";
  echo "<p>Survey ID: $SurveyID added to database</p>\n";
  echo "<h2>Add another survey</h2>\n";
}
?>

<form name="SurveyAdd" action="SurveyAdd.php" method="POST">
<p>Machine: <?PHP echo listbox_field($machines, "MachID", isset($MachID)?$MachID:""); ?></p>
<p>Date tested (YYYY-MM-DD): <input type="TEXT" name="TestDate" size="10"> <input type="CHECKBOX" Name="today">Today</p>
<p>Tested by:
<select name="Tester1ID" size=1>
  <option value="0"></option>
<?PHP
while (list($key,$val)=mysql_fetch_array($testers)) {
  echo "<option value=\"$key\">$val</option>\n";
}
mysql_data_seek($testers,0);
?>
</select>
</p>
<p>Tested by:
<select name="Tester2ID" size=1>
  <option value="0"></option>
<?PHP
while (list($key,$val)=mysql_fetch_array($testers)) {
  echo "<option value=\"$key\">$val</option>\n";
}
mysql_data_seek($testers,0);
?>
</select>
<p>Type of test: <?PHP echo listbox_field($test, "TypeID", "1"); ?></p>
<p>Notes: <textarea name="Notes" rows="3" cols="70">Enter any notes about this survey</textarea></p>
<p>Accession: <input type="TEXT" name="Accession" size="12"></p>

<!-- A small menu -->
<p>
<input type="SUBMIT" value="Add survey"> /
<input type="RESET" value="Reset"> /
<a href="index.html" target="_top" >Main</a></p>
</form>
<?PHP
/*
  This is processed if we already have info about a survey
  (i.e. we have entered the form again after submitting survey info).
  In this case, data on the survey has already been inserted into the
  database, and now the next step is to either enter data from
  the generator check or enter any recommendations from the survey.

  $SurveyID and $MachID are passed to the next form using HIDDEN
  form elements
*/
if (isset($MachID) && isset($SurveyID)) {
  echo "<form action=\"SurveyGenDataA.php\" method=\"POST\">\n";
  echo "<input type=\"HIDDEN\" name=\"SurveyID\" value=\"$SurveyID\">\n";
  echo "<input type=\"HIDDEN\" name=\"MachID\" value=\"$MachID\">\n";
  echo "<input type=\"SUBMIT\" value=\"Add Generator data\" name=\"AddGenData\"> \n";
  echo "</form>";
  echo "<form action=\"SurveyAddRec.php\" method=\"POST\">\n";
  echo "<input type=\"HIDDEN\" name=\"SurveyID\" value=\"$SurveyID\">\n"; 
  echo "<input type=\"HIDDEN\" name=\"MachID\" value=\"$MachID\">\n";
  echo "<input type=\"SUBMIT\" value=\"Add Recommendations\" name=\"AddRec\">\n";
  echo "</form>\n";
}
?>
</body>
</html>
